<?php
session_start();
	/* Allows users to select a grocery type, shows existing grocery types
	* A section to enter a new grocery type is provided. */
	
	if (isset($_SESSION['auth'])) {
		if($_SESSION['auth'] == "yes") 
		{
			
		} else {
			echo ("hello hacker ... got you ...");  
			exit();
		}
	} else {
	echo ("hello hacker ... got you ..."); 
	exit();
	}
?>

<html>
<head>
 <title> Grocery Categories</title>
 <style type='text/css'>
 <!--
   #new { border: thin solid; margin: 1em0; padding: 1em;
		  }
   #radio { padding-bottom: 1em; }
   .field { padding-top: .5em; }
   label { font-weight: bold; }
   #new label { width: 20%; float: left;
		  	  margin-right: 1em; text-align: right; }
   input { margin-left: 1em; }
   #new input { margin-left: 0 }
 -->
  </style>
 </head>
 
 <body style='margin: 1em'>
  <h3> Select a category for the grocery you're adding.</h3>
  <p>If you are adding a grocery in a category that is not
	 listed, choose <b>New Category</b> and type the
	 name and the description of the category. Press
	 <b>Submit Category</b> when you have finished
	 selecting an existing category or typing a new
	 category.</p>
<?php
  include("misc.inc");
  $cxn = mysqli_connect($host,$user,$passwd,$dbname)
		 or die ("Couldn't connect to server");
  $query="SELECT groceryType FROM groceryType
									ORDER BY groceryType";
  $result = mysqli_query($cxn,$query)
				   or die ("Couldn't execute query.");
				   
	/* Display form for selecting grocery type */
	echo "<form action='ChooseGroceryLabel.php'
					method='post'>\n";
	$counter=0;
	while($row = mysqli_fetch_assoc($result))
	{
		extract($row);
		echo "<label><input type='radio' name='category'
							value='$groceryType'";
			   if($counter == 0)
			   {
				  echo " checked='checked'";
			   }
		echo " />$groceryType </label>\n";
		$counter++;
	}
?>
<div id="new">
  <div id="radio">
    <label for="category">New Category</label>
	 <input type="radio" name="category" id="category"
			 value="new" />
  </div>
  <div class="field">
   <label for="newCat">Category name: </label>
    <input type="text" name="newCat" size="20"
		   id="newCat" maxlength="20" /></div>
	<div class="field">	   
    <label for="newDesc">Category description: </label>
	 <input type="text" name="newDesc" id="newDesc"
			size="70%" maxlength="255"  /></div>
</div>
<input type='submit' value='Submit Category'  />
</form>
<body>
<html>